/**
 * 
 */
package com.deitel.advjhtp1.gui.tabbedpane;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import com.deitel.advjhtp1.gui.webbrowser.WebBrowserPane;
import com.deitel.advjhtp1.gui.webbrowser.WebToolBar;

/**
 * @author Aslanbek
 *
 */
public class TabbedPaneWebBrowser extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8371552594934231021L;
	private JTabbedPane tabbedPane = new JTabbedPane();
	
	public TabbedPaneWebBrowser()
	{
		super("JTabbed Web Browser");
		
		createNewTab();
		
		getContentPane().add(tabbedPane);
		
		JMenu fileMenu = new JMenu("File");
		fileMenu.add(new NewTabAction());
		fileMenu.addSeparator();
		fileMenu.add(new ExitAction());
		fileMenu.setMnemonic('F');
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.add(fileMenu);
		setJMenuBar(menuBar);
	}

	private void createNewTab() {
		
		JPanel panel = new JPanel(new BorderLayout());
		WebBrowserPane browserPane = new WebBrowserPane();
		WebToolBar toolBar = new WebToolBar(browserPane);
		
		panel.add(toolBar, BorderLayout.NORTH);
		panel.add(new JScrollPane(browserPane),BorderLayout.CENTER);
		
		tabbedPane.addTab("Browser "+tabbedPane.getTabCount(), panel);
		
	}

	private class NewTabAction extends AbstractAction
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = -6268756875920852071L;

		public NewTabAction()
		{
			putValue(Action.NAME, "New Broser Tab");
			putValue(Action.SHORT_DESCRIPTION, "Create new web browser tab");
			putValue(Action.MNEMONIC_KEY, new Integer('N'));
		}
		
		public void actionPerformed(ActionEvent event)
		{
			createNewTab();
		}
	}
	
	private class ExitAction extends AbstractAction
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = 6178373459302948354L;

		public ExitAction()
		{
			putValue(Action.NAME, "Exit");
			putValue(Action.SHORT_DESCRIPTION, "Exit Application");
			putValue(Action.MNEMONIC_KEY, new Integer('x'));
		}
		
		public void actionPerformed(ActionEvent event)
		{
			System.exit(0);
		}
	}
	
	public static void main(String args[]) {
		
		TabbedPaneWebBrowser browser = new TabbedPaneWebBrowser();
		browser.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		browser.setSize(640, 480);
		browser.setVisible(true);
	}
}
